﻿using Common;
using DAL.DBUtility;
using Model.Sys;
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DAL.Sys
{
   public  class MenuDAl
    {
       //根据角色id得到菜单
       public string GetMenuByRoleId(string id)
       {
           if (id == "0")
           {
               return "";
           }
           string strSql = " select MenuId from Sys_Role where ID=@ID";
           SqlParameter[] parameters = {
					new SqlParameter("@ID", id)
            };
           return DbHelperSQL.GetSingle(strSql.ToString(), parameters).ToString();

       }
       //根据菜单id得到菜单信息
       public List<MenuModel> GetParentMenuByIds(string ids)
       {
         
           string strSql = string.Format("select * from Sys_Menu where StatusID=0 and ID  in ({0}) and ParentId=0", ids);
           return ListDataSet.DataSetToIList<MenuModel>(DbHelperSQL.GetTable(strSql)).ToList();

       }
       //根据父级菜单id得到子级菜单
       public List<MenuModel> GetSubMenuByParentId(string ParentId,string ids)
       {
           string strSql = string.Format("select * from Sys_Menu where StatusID=0 and ParentId ={0} and ID  in ({1})", ParentId,ids);
           return ListDataSet.DataSetToIList<MenuModel>(DbHelperSQL.GetTable(strSql)).ToList();

       }

       /// <summary>
       /// 获得所有菜单信息
       /// </summary>
       /// <returns></returns>
       public List<ztreemodel> GetAllMenu()
       {
           string sql = @"select ID as id,ParentId as pId,MenuName as name,'false' as [open] from Sys_Menu";
           return ListDataSet.DataSetToIList<ztreemodel>(DbHelperSQL.GetTable(sql)).ToList();
       }
    }
}
